import Vue from "vue";
import VueRouter from "vue-router";
import zyh from "./zyh"
import yzc from "./yzc"
import yl from "./yl"
import yd from "./yd"
import { Dialog } from 'vant';
Vue.use(VueRouter);
const routes = [
  ...zyh, ...yzc, ...yl, ...yd,
  {
    path: "*",
    name: "no",
    component: () => import("../components/no.vue"),
  },
];

const router = new VueRouter({
  base: process.env.BASE_URL,
  mode: 'history',
  routes,
});
router.beforeEach((to, from, next) => {
  if (to.path == "/privilege" || to.path == "/Comments" || to.path == "/orderlist" || to.path == "/coupon") {
    next(false)
    if (window.localStorage.getItem("user")) {
      next(true);
    }
    else {
      // 下一步必须
      Dialog.alert({
        title: '提示',
        message: '请您先登录!!!',
      }).then(() => {
        next("/login");
      });

    }

  }
  next(true)
});

export default router;
